<%-- 
    Document   : productDetails
    Created on : Jan 3, 2013, 5:09:03 PM
    Author     : berto
--%>

<%@page import="java.util.List"%>
<%@page import="it.unitn.science.matr155863_148346_145963.bccastestore.items.Asta"%>
<%@page import="it.unitn.science.matr155863_148346_145963.bccastestore.items.User"%>
<%@page import="it.unitn.science.matr155863_148346_145963.bccastestore.items.Product"%>
<%@page import="it.unitn.science.matr155863_148346_145963.bccastestore.DBManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
         Product p=null;
        if(request.getAttribute("product")!=null){
            p=(Product)request.getAttribute("product");
        }else if(session.getAttribute("product")!=null){
            p=(Product)session.getAttribute("product");
            session.removeAttribute("product");
        }else{
            request.setAttribute("error_message", "Unable to find your product");
            throw new Exception();
        }
        String mess=null;
         if(request.getAttribute("mess")!=null){
            mess=(String)request.getAttribute("mess");
         }else if(session.getAttribute("mess")!=null){
            mess=(String)session.getAttribute("mess");
            session.removeAttribute("mess");
         }
        
        List<Asta> asteProdotto=null;
        if(request.getAttribute("aste")!=null){
            asteProdotto=(List<Asta>)request.getAttribute("aste");
        }
        
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Product Details</title>
    </head>
    <body>
        <h2>Product Details</h2>
        <%=mess!=null? "<h3>"+mess+"</h3>":""%>
        <div class="content">
            <h2><%=p.getName()%></h2>
            <img src="<%=request.getContextPath()%>/immagini/prodotti/<%=p.getImageName()%>"/>
            <div class="details">
                <h4>Quantity:</h4><p><%=p.getQuantity()%> <%=p.getUmName()%> ;</p>
                <h4>Description:</h4><p><%=p.getHumanDescription()%> ;</p>
                <h4>Seller:</h4>
                <a href="<%=response.encodeURL(request.getContextPath()+"/contents/user/userDetails?id="+p.getSellerId())%>"
                           ><p><%=p.getSellerName()%></p> </a> 
                <h4>Aste actived:</h4>
                <%  
                int asteAtt=0;
                if(asteProdotto!=null){
                    for(Asta a:asteProdotto){
                        if(!a.getAnnulled()){
                            asteAtt++;
                        %>   
                            <li><a href="<%=request.getContextPath()%>/contents/user/addOffer?id=<%=a.getId()%>" title="addOffer <%=a.getId()%>"><h3><%=a.getSeller().getUsername()%></h3></a></li>
                        <%
                        }
                    }    
                 }
                 if(asteAtt==0){
                    %>
                    <p>There isn't any active asta</p>
                    <%
                 }
                 if(p.getSellerId()==((User)session.getAttribute("user")).getId()){
                    %>
                    <a href="<%=response.encodeURL(request.getContextPath()+"/contents/user/addAsta.jsp?pr="+p.getId())%>">
                        <h4>Create new asta for this product</h4></a>
                    <a href="<%=response.encodeURL(request.getContextPath()+"/contents/user/editProduct?id="+p.getId())%>">
                        <h4>Edit this product</h4></a>
                    <%
                }
                %>
            </div>
        </div>
    </body>
</html>
